<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="线索名称">
              <a-input placeholder="请输入线索名称" v-model="queryParam.clueName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="分配状态">
              <j-dict-select-tag v-model="queryParam.isReceive" title="状态" dictCode="clueIsReceive" placeholder="请选择状态" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="线索来源">
              <j-dict-select-tag v-model="queryParam.origin" title="线索来源" dictCode="clueOrigin" placeholder="请选择来源" />
            </a-form-item>
          </a-col>
           <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="标记状态">
              <j-dict-select-tag v-model="queryParam.sign" title="标记状态" dictCode="clueSign" placeholder="请选择状态" />
            </a-form-item>
          </a-col> 
          </a-col>
           <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="转化状态">
              <j-dict-select-tag v-model="queryParam.isTransform" title="转化状态" dictCode="transform" placeholder="请选择状态" />
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <!-- <a-button type="primary" icon="download" @click="handleExportXls('线索')">导出</a-button> -->
      <a-button type="primary" icon="download" @click="handleExportFile('线索模板','crm/clue/exportModel')">模板下载</a-button>
      <a-upload
        name="file"
        :showUploadList="false"
        :multiple="false"
        :headers="tokenHeader"
        :action="importDouUrl"
        @change="handleImportExcel"
      >
        <a-button type="primary" icon="import">导入Dou+</a-button>
      </a-upload>
      <a-upload
        name="file"
        :showUploadList="false"
        :multiple="false"
        :headers="tokenHeader"
        :action="importExcel"
        @change="handleImportExcel"
      >
        <a-button type="primary" icon="import">导入Excel</a-button>
      </a-upload>
      <a-button type="primary"  @click="handleAppointAll()" >一健分配</a-button>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        @change="handleTableChange"
        :scroll="{ x: 2000 }"
        :customRow="handleClickRow"
      >
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="look(record)">查看</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
              <a-menu-item v-show="record.isReceive==0">
                <a @click="handleAppoint(record)">分配</a>
              </a-menu-item>
              <a-menu-item v-show="record.isTransform==0">
                <a @click="handleTransfer(record)">转客户</a>
              </a-menu-item>
              <!-- <a-menu-item v-show="record.isTransform==0">
                <a @click="handleMerge(record)">合并客户</a>
              </a-menu-item> -->
              <a-menu-item>
                <a @click="handleSign(record)">标记</a>
              </a-menu-item>
              <a-menu-item>
                <a @click="handleAbandon(record)">放弃</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <clue-modal ref="modalForm" @ok="modalFormOk"></clue-modal>
    <clue-look ref="lookForm" @ok="modalFormOk"></clue-look>
    <clue-appoint ref="AppointForm" @ok="modalFormOk"></clue-appoint>
    <clue-appointAll ref="AppointFormAll" @ok="modalFormOk"></clue-appointAll>
    <clue-transfer ref="TransferForm" @ok="modalFormOk"></clue-transfer>
    <clue-merge ref="MergeForm" @ok="modalFormOk"></clue-merge>
    <clue-modal ref="RecordForm" @ok="modalFormOk"></clue-modal>
    <clue-abandon ref="AbandonForm" @ok="modalFormOk"></clue-abandon>
    <clue-sign ref="SignForm" @ok="modalFormOk"></clue-sign>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import ClueLook from './modules/ClueLook'
import ClueModal from './modules/ClueModal'
import ClueAbandon from './modules/ClueAbandon'
import ClueAppoint from './modules/ClueAppoint'
import ClueAppointAll from './modules/ClueAppointAll'
import ClueMerge from './modules/ClueMerge'
import ClueTransfer from './modules/ClueTransfer'
import ClueSign from './modules/ClueSign'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { filterDictTextByCache } from '@/components/dict/JDictSelectUtil'
import {getPcaText,getPcaCode} from '@/utils/areaUtil'
import { httpAction } from '@/api/manage'

export default {
  name: 'ClueList',
  mixins: [JeecgListMixin],
  components: {
    ClueLook,
    ClueModal,
    ClueAbandon,
    ClueAppoint,
    ClueAppointAll,
    ClueMerge,
    ClueTransfer,
    ClueSign,
  },
  data() {
    return {
      description: '线索管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },

        {
          title: '线索名称',
          align: 'center',
          dataIndex: 'clueName',
          width: 150,
          ellipsis: true
        }, 
        {
          title: '联系人',
          align: 'center',
          dataIndex: 'relaName',
          width: 130,
          ellipsis: true
        },
        {
          title: '手机号',
          align: 'center',
          dataIndex: 'mobile',
          width: 95,
        },
        {
          title: '分配状态',
          align: 'center',
          dataIndex: 'isReceive',
           customRender: (text) => {
            return filterDictTextByCache('clueIsReceive', text)
          },
          width: 70,
        },
        {
          title: '跟进者',
          align: 'center',
          dataIndex: 'ownerUserIdText',
          width: 120,
          ellipsis: true
        },
        {
          title: '来源',
          align: 'center',
          dataIndex: 'origin',
          customRender: (text) => {
            return filterDictTextByCache('clueOrigin', text)
          },
          width: 150,
        },
        
        {
          title: '标记状态',
          align: 'center',
          dataIndex: 'sign',
           customRender: (text) => {
            return filterDictTextByCache('clueSign', text)
          },
          width: 80,
        },
        {
          title: '转化状态',
          align: 'center',
          dataIndex: 'isTransform',
           customRender: (text) => {
            return filterDictTextByCache('transform', text)
          },
          width: 80,
        },
        {
          title: '创建时间',
          align: 'center',
          dataIndex: 'createTime',
           width: 160,
        },
        {
          title: '区域',
          align: 'center',
          dataIndex: 'province',
          width: 180,
          ellipsis: true,
          customRender: (text, record) => {
            return getPcaText(text);
            // return record.province+" "+record.city+ " "+ record.region;
          }
        },
        
        {
          title: '备注',
          align: 'center',
          dataIndex: 'remark',
          width: 100,
          ellipsis: true
        },
        {
          title: '创建人',
          align: 'center',
          dataIndex: 'createIdText',
          width: 120,
          ellipsis: true
        },
        
        {
          title: '操作',
          dataIndex: 'action',
          width: 100,
          fixed: 'right',
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/crm/clue/list',
        delete: '/crm/clue/delete',
        deleteBatch: '/crm/clue/deleteBatch',
        exportXlsUrl: 'crm/clue/exportXls',
        importDouUrl: 'crm/clue/importDou',
        importExcel: 'crm/clue/importExcel',
      },
    }
  },
  computed: {
    importDouUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importDouUrl}`
    },
    importExcel: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcel}`
    },
  },
  methods: {
    
    look: function (record) {
      this.$refs.lookForm.look(record);
      this.$refs.lookForm.title = "查看";
      this.$refs.lookForm.disableSubmit = true;
    }, 
    handleAppoint: function (record) {
      this.$refs.AppointForm.edit(record);
      this.$refs.AppointForm.title = "分配";
      this.$refs.AppointForm.disableSubmit = false;
    },
    handleAppointAll: function () {
      this.$refs.AppointFormAll.edit();
      this.$refs.AppointFormAll.title = "一键分配";
      this.$refs.AppointFormAll.disableSubmit = false;
    },
    handleTransfer: function (record) {
      this.$refs.TransferForm.edit(record);
      this.$refs.TransferForm.title = "转客户";
      this.$refs.TransferForm.disableSubmit = false;
    },
    handleMerge: function (record) {
      this.$refs.MergeForm.edit(record);
      this.$refs.MergeForm.title = "合并客户";
      this.$refs.MergeForm.disableSubmit = false;
    },
    
    handleAbandon: function (record) {
      this.$refs.AbandonForm.edit(record);
      this.$refs.AbandonForm.title = "放弃";
      this.$refs.AbandonForm.disableSubmit = false;
    },
    handleSign: function (record) {
      this.$refs.SignForm.edit(record);
      this.$refs.SignForm.title = "标记";
      this.$refs.SignForm.disableSubmit = false;
    },
    handleAphandleRecordpoint: function (record) {
      this.$refs.modalForm.edit(record);
      this.$refs.modalForm.title = "标记记录";
      this.$refs.modalForm.disableSubmit = false;
    },
    
    handleClickRow(record, index){
      return {
       on: {
        dblclick: () => {
          this.look(record);
        }
       }
      }
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>